<include file="Public/min-header"/>
<link href="__PUBLIC__/plugins/daterangepicker/daterangepicker-bs3.css" rel="stylesheet" type="text/css" />
<script src="__PUBLIC__/plugins/daterangepicker/moment.min.js" type="text/javascript"></script>
<script src="__PUBLIC__/plugins/daterangepicker/daterangepicker.js" type="text/javascript"></script>
<div class="wrapper">
  <include file="Public/breadcrumb"/>
<style>
	  #fenlei_box{border: 1px solid #3297ff;position: absolute;width:450px;height:250px;overflow:hidden; z-index:9999;background:#fff;display:none;}
	  #fenlei_box li{list-style: none;color:#3297ff;text-align:left;margin-left:-20px;line-height: 32px;cursor: pointer;border-bottom:1px dashed}
	  #custom_box{border: 1px solid #3297ff;position: absolute;width:450px;height:250px;overflow:hidden; z-index:9999;background:#fff;display:none;}
	  #custom_box li{list-style: none;color:#3297ff;text-align:left;margin-left:-20px;line-height: 32px;cursor: pointer;border-bottom:1px dashed}
	  #teshu{display: none;color:red;}
</style>
    <section class="content">
        <!-- Main content --> 
        <div class="container-fluid">
            <div class="pull-right">
                <a href="javascript:history.go(-1)" data-toggle="tooltip" title="" class="btn btn-default" data-original-title="返回"><i class="fa fa-reply"></i></a>
            </div>
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title"><i class="fa fa-list"></i>任务基本信息</h3>
                </div>
                <div class="panel-body">
<!-- <span style="color: red;">此功能升级中，请稍候再试。。。</span> -->
                    <!--表单数据-->
                    <form method="post" action="{:U('crm/addvisit')}" id="order-add">
                        <div class="tab-pane" >
                            <table class="table table-bordered">
                                <tbody>
                                    
                                <tr>
                                    <td>任务名称:</td>
                                    <td>
                                    <div class="form-group ">
	                                    <div class="col-xs-4">
	                                        <input name="visit_name" id="visit_name" value="{$visit_data.visit_name}" class="form-control" placeholder="任务名称"/>	                                    
                                        </div>
                                        <div class="col-xs-4">
										    <span id="err_consignee" style="color:#F00; display:none;">任务名称不能为空</span>
                                        </div>
                                    </div>    
                                    </td>
                                </tr>
                                <tr>
                                    <td>预计拜访时间:</td>
                                    <td>
                                    <div class="form-group ">
	                                    <div class="col-xs-4">
	                                        <input name="visit_time" id="visit_time" value="{$visit_data.visit_time|date='Y-m-d H:i:s',###}" class="form-control" placeholder="预计拜访时间"/>	                                    
                                        </div>
                                    </div>    
                                    </td>
                                </tr>
								<tr>
                                    <td>拜访客户:</td>
                                    <td>
                                    <div class="form-group ">
                                        <div class="col-xs-4">
                                            <input name="custom_name" id="custom_name" class="form-control" value="{$visit_data.custom_name}" placeholder="客户公司名/手机号码搜索" oninput="custom_sousuo($(this))" autocomplete="off"/>
                                			<ul id="custom_box">
                                			</ul>
                                			<input type="hidden" name="custom_id" id="custom_id" value="{$visit_data.custom_id}"/>
                                         </div>
                                     </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td>拜访目的:</td>
                                    <td>
                                    <div class="form-group ">
	                                    <div class="col-xs-4">
	                                         <select name="visit_purpose" id="visit_purpose" class="form-control">
                                            <option <if condition="$visit_data['visit_purpose'] eq 0">selected</if> value="0">收集客户需求</option>
                                            <option <if condition="$visit_data['visit_purpose'] eq 1">selected</if> value="1">了解客户需求</option>
                                            <option <if condition="$visit_data['visit_purpose'] eq 2">selected</if> value="2">方案沟通</option>
                                            <option <if condition="$visit_data['visit_purpose'] eq 3">selected</if> value="3">商务洽谈</option>
                                            <option <if condition="$visit_data['visit_purpose'] eq 4">selected</if> value="4">售后服务</option>
                                        </select>                            
                                        </div>
                                    </div>    
                                    </td>
                                </tr>
                               <tr>
                                    <td>备注:</td>
                                    <td>
                                    <div class="form-group ">
	                                    <div class="col-xs-8">
                                        	<textarea style="width:100%; height:150px;" class="ckeditor" name="remark" id="remark">{$visit_data['remark']}</textarea>
											<span id="err_user_note" style="color:#F00; display:none;">特殊单据备注不能为空</span>
                                        </div>
                                    </div>    
                                    </td>
                                </tr>
                                <tr>
                                    <td>业务员:</td>
                                    <td>
                                    <div class="form-group ">
                                        <div class="col-xs-4">
                                            <input name="user_name" id="user_name" class="form-control" value="{$visit_data.user_name}" placeholder="业务员/手机号码搜索" oninput="kehu_sousuo($(this))" autocomplete="off"/>
                                			<ul id="fenlei_box">
                                			</ul>
                                			<input type="hidden" name="user_id" id="user_id" value="{$visit_data.user_id}"/>
                                         </div>
                                     </div>
                                    </td>
                                </tr>
                                </tbody>
                                </table>
                        </div>
                        <input type="hidden" name="id" value="{$visit_data.id}">
                        <button class="btn btn-info" type="button" onclick="checkSubmit()">
                            <i class="ace-icon fa fa-check bigger-110"></i>
                            保存
                        </button>
                    </form>
<!--以下是在线编辑器 代码 -->
<script type="text/javascript">
    /*
	 * 在线编辑器相 关配置 js
	 *  参考 地址 http://fex.baidu.com/ueditor/
	 */
    // 上传商品相册回调函数
    function call_back2(paths){
            $(".goods_xc").find('img').attr('src',paths);// 修改他的图片路径
            $(".goods_xc").find('a:eq(1)').attr('onclick',"ClearPicArr2(this)").text('删除');
            $(".goods_xc").find('#fujian').val('{$myurl}'+paths); // 设置隐藏域 要提交的值
    }
	    function ClearPicArr2(obj)
	    {
	        $(obj).parent().find('img').attr('src','/Public/images/add-button.jpg'); // 删除完服务器的, 再删除 html上的图片
			$(".goods_xc").find('#fujian').val('');
		}
	
    window.UEDITOR_Admin_URL = "__ROOT__/Public/plugins/Ueditor/";
    var URL_upload = "https://{:$_SERVER['HTTP_HOST']}{$URL_upload}";
    var URL_fileUp = "http://{:$_SERVER['HTTP_HOST']}{$URL_fileUp}";
    var URL_scrawlUp = "http://{:$_SERVER['HTTP_HOST']}{$URL_scrawlUp}";
    var URL_getRemoteImage = "http://{:$_SERVER['HTTP_HOST']}{$URL_getRemoteImage}";
    var URL_imageManager = "http://{:$_SERVER['HTTP_HOST']}{$URL_imageManager}";
    var URL_imageUp = "http://{:$_SERVER['HTTP_HOST']}{$URL_imageUp}";
    var URL_getMovie = "http://{:$_SERVER['HTTP_HOST']}{$URL_getMovie}";
    var URL_home = "http://{:$_SERVER['HTTP_HOST']}{$URL_home}";
</script>
<script type="text/javascript" charset="utf-8" src="__ROOT__/Public/plugins/Ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__ROOT__/Public/plugins/Ueditor/ueditor.all.min.js"> </script>
<script type="text/javascript" charset="utf-8" src="__ROOT__/Public/plugins/Ueditor/lang/zh-cn/zh-cn.js"></script>
<script>
    var editor;
    $(function () {
        //具体参数配置在  editor_config.js  中
        var options = {
            zIndex: 999,
            initialFrameWidth: "95%", //初化宽度
            initialFrameHeight: 220, //初化高度
            focus: false, //初始化时，是否让编辑器获得焦点true或false
            maximumWords: 99999, removeFormatAttributes: 'class,style,lang,width,height,align,hspace,valign'
            , //允许的最大字符数 'fullscreen',
            pasteplain:false, //是否默认为纯文本粘贴。false为不使用纯文本粘贴，true为使用纯文本粘贴
            autoHeightEnabled: true,
        	toolbars: [
                   ['fullscreen', 'source', '|', 'undo', 'redo',
                       '|', 'bold', 'italic', 'underline', 'fontborder',
                       'strikethrough', 'superscript', 'subscript',
                       'removeformat', 'formatmatch', 'autotypeset',
                       'blockquote', 'pasteplain', '|', 'forecolor',
                       'backcolor', 'insertorderedlist',
                       'insertunorderedlist','selectall', 'cleardoc']
               ]
        };
        editor = new UE.ui.Editor(options);
        editor.render("user_note");  //  指定 textarea 的  id 为 goods_content
    }); 
	
						$('input:radio').click(function(){
						    var zhi=$(this).val();
							$("span[id^='err_']").each(function(){
								$(this).hide();
							});
							$('#add_user').hide(100);
							if(zhi==1){
								//$('#address').removeAttr('readonly');$('#address').val('');
								//$('#mobile').removeAttr('readonly');$('#mobile').val('');
								$('#biaoshi_xian').removeAttr('readonly');$('#biaoshi_xian').val('');$('#user_name').val('');$('body #teshu').show(200);$('body #dai').hide(200);
							}else{
								//$('#address').attr('readonly','readonly');
								//$('#mobile').attr('readonly','readonly');
								$('#biaoshi_xian').attr('readonly','readonly');
								$('body #teshu').hide(100);$('body #dai').show(200);
							}
							
						  });
						  
                        function checkSubmit()
						{
							var dai_type=$("input[type='radio']:checked").val();
							$("span[id^='err_']").each(function(){
								$(this).hide();
							});
							
							//if(dai_type=='1')
								//($.trim($('#user_note').val()) == '') && $('#err_user_note').show();
	
						   ($.trim($('#order_sn').val()) == '') && $('#err_order_sn').show();
						   ($.trim($('#biaoshi_xian').val()) == '') && $('#err_biaoshi_xian').show();
						   ($.trim($('#biaoqian').val()) == '0') && $('#err_biaoqian').show();
						   //($.trim($('#mobile').val()) == '') && $('#err_mobile').show();
						   if(dai_type=='0')
						   ($("input[name^='goods_id']").length ==0) && $('#err_goods').show();
						   
						   if($("span[id^='err_']:visible").length > 0 ) 
						      return false;

							$('#order-add').submit();
						}
                    </script>
                </div>
            </div>
            
        </div>    <!-- /.content -->
    </section>
</div>
<script>
function custom_sousuo(obj)
	{
	    var value = obj.val();
		if($.trim(custom_name) == '')
			return false;
		
		var dai_type=$("input[type='radio']:checked").val();
	    $.ajax({
	       type : "POST",
	       url:"/index.php?m=admin&c=crm&a=search_customer",//+tab,
	       data :{search_key:value},
	        success: function(data){
				data=JSON.parse(data);
					 if(data.code=='200'){
						$('#custom_box').show(200);
						$('#add_user').hide(100);
						$('#custom_box').html(data.selects);
					 }else{
						$('#custom_box').hide(100);
						if(dai_type==1)
						$('#add_user').show(200);
						
						$('#custom_box').html('');
					 }
	        }
	    });
	}
  
	function kehu_sousuo(obj)
	{
	    var value = obj.val();
		if($.trim(user_name) == '')
			return false;
		
		var dai_type=$("input[type='radio']:checked").val();
	    $.ajax({
	       type : "POST",
	       url:"/index.php?m=admin&c=crm&a=search_user",//+tab,
	       data :{search_key:value},
	        success: function(data){
				data=JSON.parse(data);
					 if(data.code=='200'){
						$('#fenlei_box').show(200);
						$('#add_user').hide(100);
						$('#fenlei_box').html(data.selects);
					 }else{
						$('#fenlei_box').hide(100);
						if(dai_type==1)
						$('#add_user').show(200);
						
						$('#fenlei_box').html('');
					 }
	        }
	    });
	}
function data_pick(id){
    var myDate = new Date();
    $('#'+id).daterangepicker({
    	format:"YYYY-MM-DD HH:mm:ss",
        singleDatePicker: true,
        showDropdowns: true,
        minDate:myDate.getFullYear()+'-'+myDate.getMonth()+'-'+myDate.getDate(),
        maxDate:'2030-01-01',
		timePicker : true, //是否显示小时和分钟  
        timePickerIncrement:1,//time选择递增数
		timePicker12Hour : false, //是否使用12小时制来显示时间 		
        locale : {
            applyLabel : '确定',
            cancelLabel : '取消',
            fromLabel : '起始时间',
            toLabel : '结束时间',
            customRangeLabel : '自定义',
            daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
            monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月','七月', '八月', '九月', '十月', '十一月', '十二月' ],
            firstDay : 1
        }
    });
}
    /* 用户客户选择 layer.msg('该用户不是本商城审核会员！不能代其下单。', {icon: 5});*/
    $(document).ready(function(){
		$("body").on("click", function() {
			$('#fenlei_box').hide(100);
			$('#custom_box').hide(100);
		});
		data_pick('visit_time');
		$("#fenlei_box").on("click","li", function() {
			var user_id=$(this).attr('rel'),
				company=$(this).attr('title');

			$('#user_name').val(company);
			$('#user_id').val(user_id);
		});
	    $("#custom_box").on("click","li", function() {
			var user_id=$(this).attr('rel'),
				company=$(this).attr('title');
			$('#custom_name').val(company);
			$('#custom_id').val(user_id);
		});
	$("#goods_td").on("change","input", function() {
		tongji();
	});
	
	$("#goods_td").on("click","a", function() {
		$(this).parent().parent().remove();
		tongji();
    })
	})
// 选择商品
function selectGoods(){
    var url = "{:U('Seller/Order/search_goods')}";
    layer.open({
        type: 2,
        title: '选择商品',
        shadeClose: true,
        shade: 0.8,
        area: ['80%', '80%'],
        content: url, 
    });
}
// 选择商品返回
function call_back(table_html)
{ 	//console.log(table_html);
	//$('#goods_td').empty().html('<table class="table table-bordered">'+table_html+'</table>');
	//table_html=table_html.replaceAll("javascript:$(this).parent().parent().remove();","");console.log(table_html);
	$('#goods_td .table-bordered').append(table_html);
	layer.closeAll('iframe');tongji();
}
function tongji(){
	var heji=0;
	$("#goods_td tbody tr").each(function(){
		var price=$(this).find('td').eq(1).text();
		var num=$(this).find('input').val();
		if(price!=''){
			price=parseFloat(price);num=parseFloat(num);
			heji=heji+(price*num);
		}
	  });
	  $('#z_jine').val(heji.toFixed(3));
	 //return heji.toFixed(3);
}
</script>
</body>
</html>